package com.axxy.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author 一缕茜阳
 * @date 2021/8/4
 */
public class ModelMethodTest {
    public static void main(String[] args) {
        Drink tea = new MilkTea();
        tea.makeDrink();
    }
}

interface Ingredient {
}

class Pearl implements Ingredient {

}

class Coconut implements Ingredient {

}
abstract class Drink {
    private List<Ingredient> ingredients;
    final void makeDrink() {
        getMaterial();
        if (hook()) {
            add();
        }
        packageDrink();
    }



    abstract void getMaterial();

    abstract void add();

    final void packageDrink(){
        System.out.println("打包");
    }

    boolean hook() {
        return true;
    }


}

class MilkTea extends Drink {

    private List<Ingredient> ingredientList;

    @Override
    void getMaterial() {
        System.out.println("获取原材料");
    }

    @Override
    void add() {
        getIngredients();
        for (Ingredient i :
                ingredientList) {
            System.out.println("添加" + i.getClass().getName());
        }
    }

    @Override
    boolean hook() {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());

        if (c.get(Calendar.DAY_OF_WEEK) == 7 || c.get(Calendar.DAY_OF_WEEK) == 5) {
            return true;
        }
        return false;
    }

    private void getIngredients() {
        List<Ingredient> ingredients = new ArrayList<>();
        ingredients.add(new Coconut());
        ingredients.add(new Pearl());
        ingredientList =  ingredients;
    }
}